package com.weishi.project.api.controller.selection;

import com.weishi.common.utils.DateUtils;
import com.weishi.common.utils.StringUtils;
import com.weishi.project.api.vo.appvo.SubsectionDTO;
import com.weishi.project.training.domain.HeartRateCount;
import com.weishi.project.training.domain.HeartRateRecord;
import com.weishi.project.training.vo.HeartRateCountAddVo;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 静态数据 impl 实现类方法
 */
public class WeekPlanMethod {


    /**
     * ****************************************************************************************
     */
    // 时间数据相加
    public static String timeAdd(List<String> segmentedTiming , int i , int size , int trainingMode){
        // 成绩相加
        Long lengthTime3 = DateUtils.getLongTime(segmentedTiming.get(i));
        if(trainingMode == 0){
            if(segmentedTiming.size() == 1){
                return segmentedTiming.get(i);
            }else{
                if(size == 0){
                    return segmentedTiming.get(i);
                }else{
                    for(int j = 0; j<i; j++){
                        if(size<segmentedTiming.size()){
                            Long lengthTime2 = DateUtils.getLongTime(segmentedTiming.get(j));
                            lengthTime3 += lengthTime2;
                        }
                    }
                }
            }
            return DateUtils.getStringTime_HHmmss_SS(lengthTime3);

            /**
             * 加距离
             */
        }else{
            double mileage3 = Double.valueOf(segmentedTiming.get(i));
            if(segmentedTiming.size() == 1){
                return segmentedTiming.get(i);
            }else{
                if(size == 0){
                    return segmentedTiming.get(i);
                }else{
                    if(size<segmentedTiming.size()){
                        double mileage2 = Double.valueOf(segmentedTiming.get(i));
                        mileage3 += mileage2;
                    }
                }
            }
            return String.valueOf(mileage3);
        }
    }
    // 时间数据相加 结束
    /**
     * ****************************************************************************************
     */




    /**
     * ****************************************************************************************
     */
    // 新增成绩和心率方法
    public static List<HeartRateCountAddVo> addOrSaveHeartRateCount(SubsectionDTO subsectionDTO){
        List<HeartRateCountAddVo> list = new ArrayList<>();

        HeartRateCountAddVo heartRateCountAddVo = new HeartRateCountAddVo();
        HeartRateCount heartRateCount = new HeartRateCount();
        StringUtils.copyProperties(subsectionDTO , heartRateCount);
        heartRateCount.setPropellerFrequency(subsectionDTO.getPropellerFrequency());
        heartRateCount.setChannelId(subsectionDTO.getChannelId());
        heartRateCount.setTime(new Date());
        heartRateCount.setShipSpeed(subsectionDTO.getSpeed());
        heartRateCount.setTotalDistance(subsectionDTO.getMileage());
        heartRateCount.setPointAchievement(subsectionDTO.getLengthTime());
        heartRateCount.setGroupId(subsectionDTO.getGroupId());
        heartRateCount.setTrainingDayId(subsectionDTO.getTrainingDayId());
        heartRateCount.setCtime(new Date());
        if(StringUtils.isNotNull(subsectionDTO.getShipSpeedId())){
             heartRateCount.setShipSpeedId(subsectionDTO.getShipSpeedId());
          }
            heartRateCountAddVo.setHeartRateCount(heartRateCount);

            List<HeartRateRecord> heartRateRecordList = new ArrayList<>();
            for (SubsectionDTO.Person person : subsectionDTO.getPerson()){
                HeartRateRecord heartRateRecord = new HeartRateRecord();
                if(StringUtils.isNotNull(person.getId())){
                    heartRateRecord.setId(person.getId());
                }
                heartRateRecord.setCtime(new Date());
                heartRateRecord.setSportsmanId(person.getSportsmanId());
                heartRateRecord.setHeartRateAvg(person.getHeartRate());
                heartRateRecordList.add(heartRateRecord);
                heartRateCountAddVo.setHeartRateRecords(heartRateRecordList);
            }
            list.add(heartRateCountAddVo);

        return list;
    }
    // 新增成绩和心率方法 结束
    /**
     * ****************************************************************************************
     */



    /**
     * ****************************************************************************************
     */
    // 时间数据相减
    public static String timeLess(List<String> segmentedTiming , int i , int size , int trainingMode){
        // 成绩相减
        if(trainingMode == 0){
            if(size == 1){
                Long lengthTime3 = StringUtils.turnSecond(segmentedTiming.get(size));
                Long lengthTime2 = StringUtils.turnSecond(segmentedTiming.get(size-1));
                Long lengthTime = lengthTime3 - lengthTime2;
                return StringUtils.millisecondRotationTime(lengthTime);
            }else{
                if(size == 0){
                    return segmentedTiming.get(i);
                }else{
                        if(size<segmentedTiming.size()){
                            Long lengthTime3 = StringUtils.turnSecond(segmentedTiming.get(size));
                            Long lengthTime2 = StringUtils.turnSecond(segmentedTiming.get(size-1));
                            Long lengthTime = lengthTime3 - lengthTime2;
                            System.err.println("========"+lengthTime);
                            return StringUtils.millisecondRotationTime(lengthTime);
                        }
                }
            }


            /**
             * 减距离
             */
        }else{
            double mileage3 = Double.valueOf(segmentedTiming.get(size-1));
            if(segmentedTiming.size() == 1){
                return segmentedTiming.get(i);
            }else{
                if(size == 0){
                    return segmentedTiming.get(i);
                }else{
                    if(size<segmentedTiming.size()){
                        double mileage2 = Double.valueOf(segmentedTiming.get(i));
                        mileage3 -= mileage2;
                        return String.valueOf(mileage3);
                    }
                }
            }

        }
        return null;
    }
    // 时间数据相减 结束
    /**
     * ****************************************************************************************
     */







}
